package com.cy1;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * @author CY
 * @date 2022/09/19 15:45
 * 简单的扑克牌洗牌算法
 **/
public class Pokers {
    private static final String suits[] = {"♥", "♠", "♦", "♣"};


    public static List<Poker> buyPoker() {
        ArrayList<Poker> pokers = new ArrayList<Poker>();
        for (int i = 0; i < suits.length; i++) {
            for (int j = 1; j <= 13; j++) {
                pokers.add(new Poker(suits[i], j));
            }
        }
        return pokers;
    }

    public static void main(String[] args) {
        List<Poker> pokers = buyPoker();
        Random random = new Random();
        for (int i = pokers.size() - 1; i >0; i--) {
            int j = random.nextInt(i);
            swapPoker(pokers, i, j);
        }

        ArrayList<Poker> player1 = new ArrayList<Poker>();
        ArrayList<Poker> player2 = new ArrayList<Poker>();
        ArrayList<Poker> player3 = new ArrayList<Poker>();
        ArrayList<ArrayList<Poker>> players = new ArrayList<>();
        players.add(player1);
        players.add(player2);
        players.add(player3);
        for (int i = 0; i < 16; i++) {
            for (int i1 = 0; i1 < players.size(); i1++) {
                ArrayList<Poker> tmp = players.get(i1);
                tmp.add(pokers.remove(0));
            }

        }
        System.out.print("底牌是：");
        System.out.println(pokers);
        for (int i = 0; i < players.size(); i++) {
            System.out.print("第"+ (i + 1)+"个人的牌是：");
            System.out.print(players.get(i));
            System.out.println();
        }

    }

    private static void swapPoker(List<Poker> pokers, int i, int j) {
        Poker tmp = pokers.get(i);
        pokers.set(i, pokers.get(j));
        pokers.set(j, tmp);
    }
}

